/***********************************************
 This file is part of redia-lib-utils-ios
.
 
 Copyright (c) 2014 Redia A/S
 
 Redia-library-app-ios is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 Redia-library-app-ios is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with redia-library-app-ios.  If not, see <http://www.gnu.org/licenses/>.
 
 *********************************************** */

#import <Foundation/Foundation.h>
#import "UrlCacheImageEntry.h"

typedef enum {
    LazyLoadUnknownError = 0,
    LazyLoadNetworkError = 1,
    LazyLoadParameterError = 2,
    LazyLoadUsageError = 3,
    LazyLoadDataError = 4
} LazyLoaderErrorCode;

typedef void(^LLSuccessBlock)(UIImage *image);
typedef void(^LLErrorBlock)(LazyLoaderErrorCode errorCode, NSString *errorMessage);
typedef void(^LLCancelBlock)();

@interface LazyLoadConnection : NSObject <UrlCacheEntryDelegate>

@property (strong, nonatomic) NSString *url;
@property (strong, nonatomic) LLSuccessBlock successBlock;
@property (strong, nonatomic) LLErrorBlock errorBlock;
@property (strong, nonatomic) LLCancelBlock cancelBlock;
@property (assign, nonatomic) BOOL scaleForRetina;

/** 
 * Initializes the loader and sets the required parameters.
 */
- (id)initWithUrl:(NSString*)url setScaleforRetina:(BOOL)setScaleforRetina onSuccess:(LLSuccessBlock)successBlock onError:(LLErrorBlock)errorBlock onCancel:(LLCancelBlock)cancelBlock;

/**
 * Cancel the connection. The error block will be invoked.
 */
- (void)cancel;

/**
 * Starts the loader, i.e., tells it to start downloading the content.
 */
- (void)start;

@end
